#ifndef __FLY_CUDA_MM_H__
#define __FLY_CUDA_MM_H__

#include "cuda_runtime_api.h"

#define CUDA_SAFE_MALLOC_DEVICE(PTR, BYTES) do { \
    err = cudaMalloc((void**)&PTR, BYTES); \
    if (err != cudaSuccess) { \
        LOG_ERROR("cuda malloc failed, err: %x", err); \
        return CUDA_MALLOC_FAILED; \
    } \
} while (0)

#define CUDA_SAFE_COPY_HOST_TO_DEVICE(DST, SRC, BYTES) do { \
    err = cudaMemcpy(DST, SRC, BYTES, cudaMemcpyHostToDevice); \
    if (err != cudaSuccess) { \
        LOG_ERROR("cuda copy to device failed, err: %x", err); \
        return CUDA_MEMCPY_FAEILD; \
    } \
} while (0)

#define CUDA_SAFE_COPY_DEVICE_TO_HOST(DST, SRC, BYTES) do { \
    err = cudaMemcpy(DST, SRC, BYTES, cudaMemcpyDeviceToHost); \
    if (err != cudaSuccess) { \
        LOG_ERROR("cuda copy to device failed, err: %x", err); \
        return CUDA_MEMCPY_FAEILD; \
    } \
} while (0)

#endif // __FLY_CUDA_MM_H__